package com.qidian.buy.goods.config.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Author: 戴着假发的程序员
 * Date: 2024-05-15 11:19
 * company: 起点编程
 **/
@Configuration
public class TopicRabbitConfig {
    @Bean
    public TopicExchange topicExchange(){
        // 创建一个交换机
        return new TopicExchange("topic-exchange");
    }
    // 两个队列
    @Bean
    public Queue topicA(){
        return new Queue("topicA");
    }
    @Bean
    public Queue topicB(){
        return new Queue("topicB");
    }
    @Bean
    public Queue topicC(){
        return new Queue("topicC");
    }
    // 绑定队列  路由可以使用通配符
    @Bean
    public Binding bindingTopicA(){
        // topic.a   topic.abc  topic.def
        return BindingBuilder.bind(topicA()).to(topicExchange()).with("topic.*");
    }
    @Bean
    public Binding bindingTopicB(){
        // topic.a   topic.abc  topic.def   topic.a.cb
        return BindingBuilder.bind(topicB()).to(topicExchange()).with("topic.#");
    }
    @Bean
    public Binding bindingTopicC(){
        // abc.topic   a.b.c.topic
        return BindingBuilder.bind(topicC()).to(topicExchange()).with("#.topic");
    }
}
